//
// Created by vcq on 21/2/9.
//
#pragma once
#include "dbng.hpp"
struct judge {
    int id;
    string name;
    string note;
};
REFLECTION(judge, id, name,note,note)

json MGetJudge(basic_string_view<char> id) {
    string sql = "select * from `judge` where 1=1 ";
    if (!id.empty()) {
        sql += "and id =";
        sql += id;
    }
    Dao dao;
    auto v = dao.query<judge>(sql);
    nlohmann::json article_list, ret, item;
    for (auto &o : v) {
        item["id"] = o.id;
        item["name"] = o.name;
        item["note"] = o.note;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}

void MAddJudge(const struct judge &judge1) {
    Dao dao;
    dao.update_object(judge1);
}

void MDeleteJudge(basic_string_view<char> id) {
    MDeleteAll("judge", id);
}